﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZCRS.HCMS.Entity;
using EZCRS.HCMS.Data;
using System.Data;
using System.Data.SqlClient;

namespace EZCRS.HCMS.SqlClient
{
    public class sql_AdmCreditCard
    {
        private string ErrMsg = "";
        private string SqlStr = "";
        #region 信用卡信息列表
        public DataTable CreditCard_List(string Uid)
        {
            if (Uid == "")
                return null;
            else
                return ExecSql.GetDataSet("SELECT cid, uid, creditcardtype, cardname, crank, indate, CONVERT(char(10),expirationdate, 20) AS expirationdate, SUBSTRING(creditcardno, 0, 5) + '**********' AS creditcardno FROM hfg_creditcard where uid=" +Uid + " order by crank ").Tables[0];
        }
        #endregion

        #region 信用卡信息添加、修改
        /// <summary>
        /// 修改或添加信用卡信息
        /// </summary>
        /// <returns></returns>
        public bool CreditCard_Add(string Uid, string Creditcardtype, string Creditcardno, string Expirationdate, string Cardname, string Indate, string Cid)
        {
            SqlParameter[] pam = new SqlParameter[6];
            pam[0] = new SqlParameter("@uid", Uid);
            pam[1] = new SqlParameter("@creditcardtype", Creditcardtype);
            pam[2] = new SqlParameter("@creditcardno", Creditcardno);
            pam[3] = new SqlParameter("@expirationdate", Expirationdate);
            pam[4] = new SqlParameter("@cardname", Cardname);
            pam[5] = new SqlParameter("@indate", Indate);

            if (Cid != "")
                SqlStr = "update hfg_creditcard set uid=@uid,creditcardtype=@creditcardtype,creditcardno=@creditcardno,expirationdate=@expirationdate,cardname=@cardname,indate=@indate where cid=" + Cid + "";
            else
                SqlStr = "insert into hfg_creditcard(uid,creditcardtype,creditcardno,expirationdate,cardname,indate) values(@uid,@creditcardtype,@creditcardno,@expirationdate,@cardname,@indate)";
            if (ExecSql.SqlExecNoquery(SqlStr, pam) > 0)
                return true;
            else
                return false;
        }
        #endregion

        #region 信用卡Info数据的显示,显示一条数据
        public DataRow CreditCard_Item(string Cid)
        {
            try
            {
                return ExecSql.GetDataSet("select * from hfg_creditcard where cid=" + Cid).Tables[0].Rows[0];
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 信用卡的删除
        public bool CreditCard_Del(string Cid)
        {
            string sql = "", msg = "";
            sql = "delete from hfg_creditcard where cid=" + Cid + "";
            if (ExecSql.SqlExecNoquery(sql) > 0)
                return true;
            else
                return false;
        }
        #endregion
    }
}
